package com.xh.bussiness.course.controller;

import com.xh.bussiness.course.bean.request.CoursewareDetailRequest;
import com.xh.bussiness.course.service.ICoursewareDetailService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "备课详情接口")
@RestController
@RequestMapping("/teachbook/CoursewareDetail")
public class CoursewareDetailController {
    @Autowired
    ICoursewareDetailService coursewareDetailService;

    @ApiOperation(value = "备课详情查询", notes = "备课详情查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课详情信息", required = true, dataType = "CoursewareDetailRequest")
    })
    @PostMapping("/query")
    public AjaxResult query(CoursewareDetailRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareDetailService.query(request));
    }


    @ApiOperation(value = "备课更新", notes = "备课更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课信息", required = true, dataType = "coursewareRequest")
    })
    @PostMapping("/modify")
    @ResponseBody
    public AjaxResult modify(CoursewareDetailRequest request) {
        if(null == request.getId()){
            return new AjaxResult(AjaxResultConstant.Result.ERROR, "参数错误：id不能为空");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareDetailService.modify(request));
    }

    @ApiOperation(value = "备课保存", notes = "备课保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课信息", required = true, dataType = "coursewareRequest")
    })
    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestBody  List<CoursewareDetailRequest> request) {
        if(CollectionUtils.isEmpty(request)){
            return new AjaxResult(AjaxResultConstant.Result.ERROR, "参数错误");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareDetailService.save(request));
    }
}
